\defmodule {ChiSquareGen}

This class implements random variate generators with the
{\em chi square\/} distribution with $n>0$ degrees of freedom.
Its density function is 
\begin{htmlonly}
\eq 
  f(x) = x^{n/2-1}e^{-x/2}/(2^{n/2}\Gamma(n/2))\mbox{ for } x > 0, 0\mbox { elsewhere}
\endeq
\end{htmlonly}
\begin{latexonly}
\eq
  f(x) = 
   \frac{e^{-x/2}x^{n/2-1}}{2^{n/2}\Gamma(n/2)}
   \qquad\mbox{ for } x > 0,        \eqlabel{eq:Fchi2}
\endeq
\end{latexonly}
where $\Gamma (x)$ is the gamma function defined
in\latex{ (\ref{eq:Gamma})}\html{ \class{GammaGen}}.

% No local copy of the parameter $n$ is maintained in this class.
The (non-static) \texttt{nextDouble} method simply calls \texttt{inverseF} on the
distribution.

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        ChiSquareGen
 * Description:  random variate generators with the chi square distribution
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
\end{hide}

public class ChiSquareGen extends RandomVariateGen \begin{hide} {
   protected int n = -1;
    
\end{hide}
\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Constructors}
\begin{code}

   public ChiSquareGen (RandomStream s, int n) \begin{hide} {
      super (s, new ChiSquareDist(n));
      setParams (n);
   }\end{hide}
\end{code} 
\begin{tabb}  Creates a \emph{chi square}  random variate generator with 
 $n$ degrees of freedom, using stream \texttt{s}. 
\end{tabb}
\begin{code}
 
   public ChiSquareGen (RandomStream s, ChiSquareDist dist) \begin{hide} {
      super (s, dist);
      if (dist != null)
         setParams (dist.getN ());
   }\end{hide}
\end{code}
  \begin{tabb}  Create a new generator for the distribution \texttt{dist}
    and stream \texttt{s}. 
  \end{tabb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
\subsubsection* {Methods}
\begin{code}

   public static double nextDouble (RandomStream s, int n) \begin{hide} {
      return ChiSquareDist.inverseF (n, s.nextDouble());
   }
\end{hide}
\end{code}
 \begin{tabb}  Generates a new variate from the chi square distribution 
   with $n$ degrees of freedom, using stream \texttt{s}.
 \end{tabb}
\begin{code} 
     
   public int getN()\begin{hide} {
      return n;
   }
\end{hide}
\end{code}
\begin{tabb}
  Returns the value of $n$ for this object.
\end{tabb}
\begin{hide}\begin{code} 
     
   protected void setParams (int n) {
      if (n <= 0)
         throw new IllegalArgumentException ("n <= 0");
      this.n = n;
   }
}
\end{code}
\end{hide}
